﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
using Blog.IRepository;
using Blog.Repository;
namespace Blog.RepositoryContainer
{
    public class Container
    {
        public static IContainer container = null;
        public static T Resolve<T>() {
            try
            {
                Initialize();
            }
            catch (Exception ex)
            {
                throw new System.Exception("IOC实例化出错！" + ex.Message);
            }
            return container.Resolve<T>();
        }
        public static void Initialize() {
            var builder = new ContainerBuilder();
            builder.RegisterType<UserInfoRespository>().As<IUserInfoRepository>().InstancePerLifetimeScope();
            builder.RegisterType<AdminRespository>().As<IAdminRepository>().InstancePerLifetimeScope();
            builder.RegisterType<CommentRepository>().As<ICommentRepository>().InstancePerLifetimeScope();
            builder.RegisterType<UserInfoRespository>().As<IUserInfoRepository>().InstancePerLifetimeScope();
            builder.RegisterType<ArticleRepository>().As<IArticleRepository>().InstancePerLifetimeScope();
            builder.RegisterType<AttentRepository>().As<IAttentRepository>().InstancePerLifetimeScope();
            builder.RegisterType<CategoryRepository>().As<ICategoryRepository>().InstancePerLifetimeScope();
            builder.RegisterType<ParentRepository>().As<IParentRepository>().InstancePerLifetimeScope();
            builder.RegisterType<ProblemRespository>().As<IProblemRepository>().InstancePerLifetimeScope();
            builder.RegisterType<WorkOrderRespository>().As<IWorkOrderRepository>().InstancePerLifetimeScope();
            container =builder.Build();
        }
    }
}
